<template>
  <div id="rolllist" > 


          <el-table :data="datalist" style="width: 100%" :row-class-name="tableRowClassName" 
           :border="true" :height="dtheight" :header-cell-style="{background:'#4F81BC',color:'white'}"
          >
                
                 <el-table-column label="排序"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.sort }}</span>
                    </template>
                </el-table-column>
                 <el-table-column label="内容"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.content }}</span>
                    </template>
                </el-table-column>
                 <el-table-column label="操作" align='center' >
                    <template slot-scope="scope">
                         <el-button size="mini"  type="primary"  plain class="button_class1" @click="mtk2_but(scope.row)">排序</el-button> 
                        <el-button size="mini"  type="primary"  plain class="button_class1" @click="mtk1_but(scope.row)">修改</el-button> 
                        <el-button size="mini"  type="primary"  plain class="button_class2" @click="delect_but(scope.row)">删除</el-button> 
                    </template>
                </el-table-column>

            </el-table>  


     <el-dialog title="修改公告" :visible.sync="mtk1"  width="500px" >
          <el-form ref="form"   label-width="80px" style="width:100%;">
                 <el-form-item label="添加内容">
                    <el-input v-model="mtk1_form.content" type="textarea" :rows="4" placeholder="必填"></el-input>
                </el-form-item>

         </el-form>
          <div style="text-align: center;width:70%;margin:auto;">
                  <el-button type="primary" class="custom_color_button" style="width:80%;" @click="mtk1_but_qr()">确认</el-button>
          </div>

   </el-dialog> 

       <el-dialog title="修改排序" :visible.sync="mtk2"  width="350px" >
          <el-form ref="form"   label-width="80px" style="width:100%;">
                 <el-form-item label="修改排序">
                    <el-input v-model="mtk2_form.num"  :rows="4" placeholder="必填"></el-input>
                </el-form-item>

         </el-form>
          <div style="text-align: center;width:70%;margin:auto;">
                  <el-button type="primary" class="custom_color_button" style="width:80%;" @click="mtk2_but_qr()">确认</el-button>
          </div>

   </el-dialog> 
 


   </div>
</template>

<script>
export default {
   name: 'rolllist',
   props:{
      datalist:{  
        //type:Array,
       default:()=>[]
     },
  },
  data () {
    return {
        dtheight:'500',  //窗口高度
        my_id:'',
        mtk1:false,
        mtk1_form:{
            content:''
        },
        mtk2:false,
        mtk2_form:{
            num:''
        }
    }
  },
   components:{

  },
  created(){
     this.dtheight = window.innerHeight - 293
      
  },
  mounted (){
   
  },
  methods: {
    mtk2_but(row){
       this.my_id = row.id
       this.mtk2_form.num = row.sort
       this.mtk2 = true
    },
    mtk2_but_qr(){
       this.post("/newspaper/updateSort", {
                id:this.my_id,
                num:this.mtk2_form.num,
            }).then(res => {
                if(res.error_code == 0){
                    this.open1(res.result,'success')  //提示框
                    this.mtk2 = false
                    this.$emit('up_list_fun')
                }else {
                this.open1(res.message,'warning')
                }

       })
    },
    mtk1_but(row){
         this.my_id = row.id
         this.mtk1_form.content = row.content
         this.mtk1 = true
    },
    mtk1_but_qr(){
        this.post("/newspaper/updateRoll", {
                id:this.my_id,
                content:this.mtk1_form.content,
            }).then(res => {
                if(res.error_code == 0){
                    this.open1(res.result,'success')  //提示框
                    this.mtk1 = false
                    this.$emit('up_list_fun')
                }else {
                this.open1(res.message,'warning')
                }

       })
    },
    
    delect_but(row){
         this.my_id = row.id
        this.$confirm('是否删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
             this.post("/newspaper/delRoll", {
                    id:this.my_id,
                }).then(res => {
                    if(res.error_code == 0){
                      this.open1(res.result,'success')  //提示框
                      this.$emit('up_list_fun')
                      this.my_id = ''
                    }else {
                    this.open1(res.message,'warning')
                    }

              })
        })


    },


  }
}
</script>


<style scoped>

</style>